<template>
	<view class="KingKongDistrict Row">
		<navigator class="child" url="/pages/index/materialRequisition/materialRequisition" hover-class="none">
			<view class="icon">
				<image class="photoSize" src="/static/applyFor.png" mode="aspectFill"></image>
			</view>
			<view class="text">产品商城</view>
		</navigator>
		<view class="child" @click="jumpPage('/pages/mine/device/device')">
			<view class="icon">
				<image class="photoSize" src="/static/sheBei.png" mode="aspectFill"></image>
			</view>
			<view class="text">设备列表</view>
		</view>

		<view class="child" @click="jumpPage('/pages/index/teamUsers/teamUsers')">
			<view class="icon">
				<image class="photoSize" src="/static/team.png" mode="aspectFill"></image>
			</view>
			<view class="text">合伙人列表</view>
		</view>
		<view class="child" @click="inviterQrcode">
			<view class="icon">
				<image class="photoSize" src="/static/qrCode.png" mode="aspectFill"></image>
			</view>
			<view class="text">分享二维码</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "homeMenu",
		props: {
			// 是否需要登录验证
			requireLogin: {
				type: Boolean,
				default: true,
			},
		},
		data() {
			return {
				// 菜单数据
				homeItems: [{
						icon: '&#xe609;',
						label: "全部订单",
						url: "./allOrders/allOrders",
					},
					{
						icon: "&#xe78e;",
						label: "地址管理",
						url: "/pages/mine/shipAddress/shipAddress",
					},
					// {
					// 	icon: "&#xe60c;",
					// 	label: "设备列表",
					// 	url: "/pages/mine/device/device",
					// },
				],
			};
		},
		methods: {
			/* 邀请人二维码 */
			inviterQrcode() {
				const token = uni.getStorageSync('token');
				if (!token) {
					uni.$u.toast("请登录后操作");
					return;
				}
				this.getUserInfo(); // 获取用户当前等级
			},
			getUserInfo() {
				let that = this;
				uni.$u.http.post('/user/getUserInfo').then(res => {
					let userId = res.data.userinfo.group.id;
					// console.log(userId)
					if (userId == 1) {
						uni.$u.toast("您还未获取推广资格，请升级会员");
						return;
					}

					uni.navigateTo({
						url: "/pages/mine/inviterQrcode/inviterQrcode",
					})
				}).catch(err => {
					console.log(err)
				})
			},
			
			jumpPage(Url) {
				const that = this;
				let inviter = uni.getStorageSync('inviter');
				let token = uni.getStorageSync('token');
				
				if (!token) {
					uni.$u.toast('请登录后操作');
					return;
				}
				if (!inviter && Url == "/pages/mine/device/device") {
					uni.$u.toast('请绑定邀请人后操作');
					return;
				}
				
				uni.navigateTo({
					url: Url
				})
			},
			train() {
				uni.navigateTo({
					url: "/pages/index/train/train"
				})
			},
			developmentTeam() {
				let that = this;
				if (!that.token) {
					uni.$u.toast('请登录后操作');
					return;
				}

				uni.$u.http.post('/user/getUserInfo').then(res => {
					let level_id = res.data.userinfo.level_id;
					if (level_id == 1) {
						uni.$u.toast('无推荐权限');
						return;
					} else {
						uni.navigateTo({
							url: "/pages/index/developmentTeam/developmentTeam"
						})
					}
				}).catch(err => {
					console.log(err)
				})
			}
		}
	}
</script>

<style lang="scss">
	.KingKongDistrict {
		width: 100%;
		flex-wrap: wrap;
		justify-content: space-between;
		margin: 0 0 20rpx;

		.child {
			width: 25%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin-bottom: 20rpx;

			.icon {
				width: 70rpx;
				height: 70rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 38rpx;
				padding: 12rpx;
			}

			.text {
				display: flex;
				text-align: center;
				font-size: 26rpx;
			}
		}
	}
</style>